package object5.library.operation;

import object5.library.Book;
import object5.library.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("借书");
        Scanner scanner = new Scanner(System.in);
        //让用户输入要借的书的编号
        System.out.println("请输入要借阅的图书的编号");
        int id = scanner.nextInt();
        if(id == 0||id >= bookList.getSize()){
            System.out.println("您输入的编号不存在!");
            return;
        }
        //如果编号存在,判断书是否被借了出去,如果未被借出,直接输出书的编号即可
        Book book = bookList.getBook(id);
        if(book.isBorrowed()){
            System.out.println("该书已经被借出了");
            return;
        }else{
            book.setBorrowed(true);
            System.out.println("借书成功!");
        }
    }
}
